<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
</head>
<body>
<div class="container">
    <form id="socialForm" method="post" action="/social" style="display: none">
        <input type="hidden" id="type" name="type">
        <input type="hidden" id="code" name="code">
    </form>
</div>
<script>
    function param2Obj(url) {
        const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
        if (!search) {
            return {}
        }
        const obj = {}
        const searchArr = search.split('&')
        searchArr.forEach(v => {
            const index = v.indexOf('=')
            if (index !== -1) {
                const name = v.substring(0, index)
                obj[name] = v.substring(index + 1, v.length)
            }
        })
        return obj
    }

    const code = param2Obj(window.location.href)['code'];
    if (code) {
        document.getElementById('type').value = window.sessionStorage.getItem("type")
        document.getElementById('code').value = code
        document.getElementById('socialForm').submit()
    }

    function social(type, uri) {
        window.sessionStorage.setItem('type', type)
        window.location.href = uri
    }
</script>
</body>
</html>
